import numpy as np
import cv2 as cv
from PIL import Image
#相同类型的图像进行相加cv.add()
x = np.uint8([10])
y = np.uint8([250])
print(cv.add(x,y))  #[[255]]
print(x+y)       #[4]

#图像按照不同的权重进行相加 cv.addWeigthed()  dst=α⋅img1+β⋅img2+γ
img2 = Image.open('1.png')
img2 = img2.resize((220,155),Image.ANTIALIAS)
img2.save('1.png','PNG')
img1 = cv.imread('car.png')
img2 = cv.imread('1.png')
img = cv.addWeighted(img1,0.3,img2,0.7,0)
cv.imshow('img',img)
cv.waitKey(0)
cv.destroyAllWindows()

#图像的与或操作
# Load two images
img1 = cv.imread('car.png')
img2 = cv.imread('1.png')
# I want to put logo on top-left corner, So I create a ROI
rows,cols,channels = img2.shape
roi = img1[0:rows, 0:cols]
# Now create a mask of logo and create its inverse mask also
img2gray = cv.cvtColor(img2,cv.COLOR_BGR2GRAY)
ret, mask = cv.threshold(img2gray, 10, 255, cv.THRESH_BINARY)  #cv2.threshold (源图片, 阈值, 填充色, 阈值类型)
mask_inv = cv.bitwise_not(mask)
# Now black-out the area of logo in ROI
img1_bg = cv.bitwise_and(roi,roi,mask = mask_inv)
# Take only region of logo from logo image.
img2_fg = cv.bitwise_and(img2,img2,mask = mask)
# Put logo in ROI and modify the main image
dst = cv.add(img1_bg,img2_fg)
img1[0:rows, 0:cols ] = dst
cv.imshow('res',img1)
cv.waitKey(0)
cv.destroyAllWindows()